package com.demo.spzx.manager.service.impl;

import cn.hutool.core.lang.UUID;
import com.demo.spzx.manager.mapper.SysUserMapper;
import com.demo.spzx.manager.service.SysUserService;
import com.demo.spzx.model.dto.system.LoginDto;
import com.demo.spzx.model.entity.system.SysUser;
import com.demo.spzx.model.vo.system.LoginVo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.util.DigestUtils;

@Service
public class SysUserServiceImpl implements SysUserService {

    @Autowired
    private SysUserMapper sysUserMapper;

    @Override
    public LoginVo login(LoginDto loginDto, String ip) {

        String userName=loginDto.getUsername();

        String password= loginDto.getPassword();

        SysUser sysUser=sysUserMapper.selectSysUserByName(userName);

        if (sysUser== null){
            return null;
        }

        String md5password= DigestUtils.md5DigestAsHex(password.getBytes());

        if (!md5password.equals(sysUser.getPassword())){
            return null;
        }

        LoginVo loginVo=new LoginVo();

        String token= UUID.randomUUID().toString().replace("-","");
        loginVo.setToken(token);
       // loginVo.setRefresh_token();

        return loginVo;
    }
}
